<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head th:replace="common/head::head">
</head>

<body>

<div class="layui-container">
    <form action="" class="layui-form" id="form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">节点ID</label>
                <div class="layui-input-block">
                    <input type="text" id="id" name="id" placeholder="创建后不能修改"
                           class="layui-input"
                           required
                           lay-verify="required">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">节点名称</label>
                <div class="layui-input-block">
                    <input type="text" id="name" name="name" placeholder="请填写节点名称"
                           class="layui-input"
                           required
                           lay-verify="required">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">节点协议</label>
                <div class="layui-input-block">
                    <select name="protocol" lay-verify="required">
                        <option value="http">http</option>
                        <option value="https">https</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">

            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">节点地址</label>
            <div class="layui-input-block">
                <input type="text" id="url" name="url"
                       placeholder="请填写节点地址,ip:port，如：(127.0.0.1:2123)或者域名" class="layui-input"
                       required
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">安装路径</label>
            <div class="layui-input-block">
                <input type="text" id="path" name="path" placeholder="请输入插件端安装路径" class="layui-input" required
                       lay-verify="required">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">安装包</label>
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" id="selectZip">
                    <i class="layui-icon">&#xe67c;</i>选择ZIP文件
                </button>
                <div class="layui-form-mid layui-word-aux" id="zipResult"></div>
            </div>
        </div>
        <div class="layui-form-item" style="padding-left: 20%;margin-top: 20px;">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit">提交
            </button>
        </div>
    </form>
</div>
</body>
<script type="text/javascript">
    var uploadRenderData;
    var hashSelect;
    var nodeData = {};
    var installPath;
    var id = getQueryString("id");

    function loadSuccess() {
        uploadRender({
            elem: '#selectZip',
            url: './installAgentSubmit.json',
            multiple: false,
            exts: 'zip',
            acceptMime: '.zip',
            field: 'file',
            data: {
                nodeData: function () {
                    return JSON.stringify(nodeData);
                },
                path: function () {
                    return installPath;
                },
                id: id
            },
            auto: false,
            choose: function (obj) {
                hashSelect = true;
                obj.preview(function (index, file, result) {
                    $("#zipResult").html("已选择:" + file.name);
                });
            },
            done: function (res) {
                layer.msg(res.msg);
                if (200 === res.code) {
                    autoClose();
                }
            }
        }, function (data) {
            uploadRenderData = data;
        });
        form.on('submit(submit)', function (data) {
            nodeData = data.field;
            installPath = data.field.path;
            if (!hashSelect) {
                layer.msg("请选安装包");
                return false;
            }
            uploadRenderData.upload();
            return false;
        });
    }
</script>
</html>